package 笔试真题;

import java.util.Scanner;

class Node{
    int value;
    int id;
    Node left,right;
    public Node(int value,int id){
        this.value = value;
        this.id = id;
    }
}


public class Huawei202198_1 {
    private static int temp00 = 0;
    private static int sum = 0; //记录综合
    private static int compare = -1<<30; // 记录过程中最小的差值
    private static Integer ans = null; // 记录输出的节点的编号
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        Node[] nodes = new Node[n];

        for (int i = 0; i < nodes.length; i++) {
            int value = scanner.nextInt();
            nodes[i] = new Node(value,i);
            sum += value;
        }
        for (int i = 0; i < n-1; i++) {
            int first = scanner.nextInt();
            int second = scanner.nextInt();
            Node node = nodes[first];
            if(node.left==null){
                node.left = nodes[second];
            }else {
                node.right = nodes[second];
            }
        }
        for (int i = 0; i < n; i++) {
            temp00 = 0;
            dfs(nodes[i]);
            int tempCompare = Math.abs(sum- 2 * temp00);
            if(tempCompare>compare){
                ans = i;
                compare = tempCompare;
            }

        }
        System.out.println(ans);
    }
    private static void dfs(Node node) {
        if(node==null) return;
        temp00 += node.value;
        dfs(node.left);
        dfs(node.right);
    }
}
